package com.atguigu.gmail.manage.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.gmail.api.bean.PmsProductInfo;
import com.atguigu.gmail.api.bean.PmsProductImage;
import com.atguigu.gmail.api.service.SpuService;
import com.atguigu.gmail.manage.util.PmsUpLoadUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
@CrossOrigin
public class SpuController {

    @Reference
    SpuService spuService;


    @RequestMapping("spuList")
    @ResponseBody
    public List<PmsProductInfo> spuList(String catalog3Id){
        List<PmsProductInfo> pmsProductInfos = spuService.spuList(catalog3Id);
        return pmsProductInfos;
    }

    @RequestMapping("saveSpuInfo")
    @ResponseBody
    public String saveSpuInfo(@RequestBody PmsProductInfo pmsProductInfo){
        spuService.saveSpuInfo(pmsProductInfo);
        return "success";
    }



    @RequestMapping("fileUpload")
    @ResponseBody
    public String fileUpload(@RequestParam("file")MultipartFile multipartFile) {

        String imgUrl = PmsUpLoadUtil.uploadImage(multipartFile);

        return imgUrl;
    }


    @RequestMapping("spuImageList")
    @ResponseBody
    public List<PmsProductImage> spuImageList(String spuId){
        return spuService.spuImageList(spuId);
    }

}
